<%@ page language="java" import="java.util.*,shop.dao.*,shop.entity.*" 	pageEncoding="utf-8"%>
<%@ page import="myservlet.OnlineCounter" %> 
<!DOCTYPE HTML>
<html>
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
  <meta charset="UTF-8">

  <meta name="description" content="">
  <meta name="keywords" content="">

  <title>购物车</title>

    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
  <link href="css/style.css" media="screen" rel="stylesheet" type="text/css">
  <link href="css/grid.css" media="screen" rel="stylesheet" type="text/css">

  <script src="js/jquery-1.7.2.min.js" ></script>
  <script src="js/html5.js" ></script>
  <script src="js/jflow.plus.js" ></script>
  <script src="js/jquery.carouFredSel-5.2.2-packed.js"></script>
  <script src="js/checkbox.js"></script>
  <script src="js/radio.js"></script>
  <script src="js/selectBox.js"></script>

  <script>
       $(document).ready(function(){
	      $("#myController").jFlow({
		     controller: ".control", // must be class, use . sign
		     slideWrapper : "#jFlowSlider", // must be id, use # sign
		     slides: "#slider",  // the div where all your sliding divs are nested in
		     selectedWrapper: "jFlowSelected",  // just pure text, no sign
		     width: "984px",  // this is the width for the content-slider
		     height: "480px",  // this is the height for the content-slider
		     duration: 400,  // time in miliseconds to transition one slide
		     prev: ".slidprev", // must be class, use . sign
		     next: ".slidnext", // must be class, use . sign
		     auto: true
	      });
       });
  </script>
  <script>
       $(function() {
	  $('#list_product').carouFredSel({
		prev: '#prev_c1',
		next: '#next_c1',
		auto: false
	  });
          $('#list_product2').carouFredSel({
		prev: '#prev_c2',
		next: '#next_c2',
		auto: false
	  });
	  $(window).resize();
	});
  </script>
  <script>
       $(document).ready(function(){
	      $("button").click(function(){
		     $(this).addClass('click')
	      });
       })
  </script>
  <script>
       $(document).ready(function() {
	      $("select").selectBox();
       });
  </script>
  <%
     //检验是否已经登录
	String username=(String)session.getAttribute("username");
	String userSession=(String)session.getAttribute("userSession");
	if(username=="" || username==null)
	{
		out.println("<script language='javascript'>alert('请先登录!');window.location.href='login.jsp';</script>");
	}
	else
	{
		Vector cart=(Vector)session.getAttribute("cart");
		if(cart==null || cart.size()==0)
		{
			out.println("<script language='javascript'>alert('请先添加商品!');window.location.href='index.jsp';</script>");
		}

    //数据库连接 
    CartBean cb=new CartBean();
	ProductDao pt = new ProductDao();	
	TypeDao pt1 = new TypeDao();
	List pl2 = pt1.findmain_type();
	%>
	<!-- 数据库连接 -->
</head>
<body>
  <div class="container_12">
    <div id="top">
      <div class="grid_3">
        <div class="phone_top">
          Call CN +110
        </div><!-- .phone_top -->
      </div><!-- .grid_3 -->

      <div class="grid_6">
        <div class="welcome">
   <% if(session.getAttribute("userSession")!=null){%>
        上次登录的时间:<%=session.getAttribute("lasttime") %>
   &nbsp;&nbsp;&nbsp;当前在线人数:<%=OnlineCounter.getOnline()%>
         <%}  %>
        </div><!-- .welcome -->
      </div><!-- .grid_6 -->

      <div class="grid_3">
        
      </div><!-- .grid_3 -->
    </div><!-- #top -->

    <div class="clear"></div>

    <header id="branding">
      <div class="grid_3">
        <hgroup>
          <h1 id="site_logo" ><a href="index.jsp" title=""><img height="119.8" width="130.8" src="images/login.jpg" alt="Online Store Theme Logo"/></a></h1>
          <h2 id="site_description">年轻人的第一个游戏网</h2>
        </hgroup>
      </div><!-- .grid_3 -->

      <div class="grid_3">
        <form class="search" action="catalog_search.jsp" method="post">
          <input type="text" name="search" class="entry_form" value="" placeholder="寻找游戏"/>&nbsp;
	</form>
      </div><!-- .grid_3 -->

      <div class="grid_6">
        <ul id="cart_nav">
          <li>
            <a class="cart_li" href="shop_cart.jsp"><span>购物车</span></a>
              </li>
            </ul>

        <nav class="private">
          <ul>
       <% if(session.getAttribute("userSession")==null){%> 
            <li><a href="login.jsp">登录</a></li>
            <li class="separator">|</li>
            <li><a href="Create user.jsp">注册</a></li>
        <%}else{  %>
       <li><a href="##.jsp">用户(<%=session.getAttribute("username") %>)身份(<%=session.getAttribute("userSession")%>)</a>
        <li class="separator">|</li>
       <% if(session.getAttribute("userSession").equals("管理员") ){ %><li><a href="admin/ht.jsp"><span>后台</span></a></li><% } %>
       <% if(session.getAttribute("userSession").equals("客户") ){ %><li><a href="Personal.jsp"><span>个人信息</span></a></li><% } %>
       <li class="separator">|</li>
       <li> <a href="deal/logout.jsp" >[注销]</a></li>
			    <%}  %>
          </ul>
        </nav><!-- .private -->
      </div><!-- .grid_6 -->
    </header><!-- #branding -->
  </div>

  <div class="clear"></div>

  <div id="block_nav_primary">
    <div class="container_12">
      <div class="grid_12">
        <nav class="primary">
          <ul>
            <li class="curent"><a href="index.jsp">首页</a></li>
            <li><a href="blog_post.jsp">新闻</a></li>
                        <li><a href="catalog_grid.jsp">类型</a></li>
<%
	if (pl2.size() > 0) {
		for (int i = 0; i < pl2.size(); i++) {
			main_type pd2 = (main_type) pl2.get(i);			
%>
                <li><span><a href="catalog_grid.jsp?type=<%=pd2.getT_id()%>"><%=pd2.getT_type() %></a></span></li>
				<%}%>
				<%}else{ %>
                <li><span><a href="#">没有产品区</a></span></li>
				<%}%>
              </ul>
            </li>
          </ul>
        </nav><!-- .primary -->
      </div><!-- .grid_12 -->
    </div><!-- .container_12 -->
  </div><!-- .block_nav_primary -->
<form action="shop_cart.jsp" method="post">
  <div class="clear"></div>

  <section id="main" class="entire_width">
    <div class="container_12">
       <div class="grid_12">
       <h1 class="page_title">购物车</h1>
       <table class="cart_product">
	      <tr>
		     <th class="images"></th>
		     <th class="bg name">产品名字</th>
		     <th class="edit"> </th>
		     <th class="bg price">单价</th>
		     <th class="qty">数量</th>
		     <th class="bg subtotal">合计</th>
		     <th class="close"> </th>
	      </tr>
<%
		float sum=0;
		String p_id="";
		String goodsname="",goodid="";
		for(int i=0;i<cart.size();i++){	
			
			String sum1=request.getParameter("num"+i);//得到修改的数量
								
			CartBean goodsitem=(CartBean)cb.updateCart(cart,i,sum1);
			sum=sum+goodsitem.p_number*goodsitem.p_price;
			p_id=goodsitem.p_id;
			Product rs_goods=pt.findProductByID(p_id);

			goodid=rs_goods.getP_id();
			goodsname=rs_goods.getP_name();				
	%> 
	      <tr>
		     <td class="images"><a href="showProductMessage.jsp?p_id=<%=goodid%>"><img src="<%=goodsitem.p_image%>" alt="Product 6"></a></td>
		     <td class="bg name"><%=goodsname%></td>
		     <td class="edit"><a title="Edit" href="#" >Edit</a></td>
		     <td class="bg price">￥<%=goodsitem.p_price%></td>
		     <td class="qty"><input type="text" name="num<%=i%>" value="<%=goodsitem.p_number%>" placeholder="1000" onBlur="check(this.form)"/></td>
		     <td class="bg subtotal">￥<%=(goodsitem.p_price*goodsitem.p_number)%></td>
		     <td class="close"><a title="close" class="close" href="deal/cart_move.jsp?ID=<%=i%>"></a></td>
	      </tr>
<script language="javascript">
			<!--
			function check(myform){
				if(isNaN(myform.num<%=i%>.value) || myform.num<%=i%>.value.indexOf('.',0)!=-1){
					alert("请不要输入非法字符");myform.num<%=i%>.focus();return;}
				if(myform.num<%=i%>.value==""){
					alert("请输入修改的数量");myform.num<%=i%>.focus();return;}	
				myform.submit();
			}
			-->
</script>
	<%}%>
	      <tr>
		     <td colspan="7" class="cart_but">
			    <button class="continue"  onClick="window.location.href='index.jsp'"><span>icon</span><a href='index.jsp'>继续购物</a></button>
			    <button class="continue"><a  href='deal/cart_clear.jsp'>清空购物车</a></button>&nbsp;
			    
		     </td>
	      </tr>
       </table>
       </div><!-- .grid_12 -->
</form>	
       <div id="content_bottom">
        

        <div class="container_12">
          <div class="bottom_block total">     
	      <form action="payment.jsp" method="post" onSubmit="return check_pay(this);">
						  <table width="96%" border="1" bordercolor="#99CCFF" cellpadding="0" cellspacing="0" style="border-collapse:collapse">
                          <!--DWLayoutTable-->
                          <tr bgcolor="#99CCFF">
                            <td height="10" colspan="3"><!--DWLayoutEmptyCell-->
			    <h3 class="price">合计:$<%=sum%></h3></td>
                            </tr>
                          <tr>
                            <td height="20" colspan="3" bgcolor="#eeeeee">付款方式：</td>
                          </tr>
                          <tr>
                            <td width="25%" height="30" align="right"><span class="STYLE1 STYLE9">请选择您的付款方式</span><span class="STYLE9">：</span>&nbsp;</td>
							<%
								PaymentDao Pd=new PaymentDao();
								List P2=Pd.findPayment();
							%>
                            <td height="30" colspan="2"><select name="pay_fangshi">
							<option value="">-请选择付款方式-</option>
							<%
									if (P2.size() > 0) {
		for (int i = 0; i < P2.size(); i++) {
			Payment payrs = (Payment) P2.get(i);
						  %>
							<option value="<%= payrs.getPay_payment() %>"><%= payrs.getPay_payment() %></option>
						<%
								}
						%>
                            </select> </td>
                          </tr>
                          <tr>
                            <td height="30" align="right"><span class="STYLE1 STYLE9">请输入您的E_mail</span><span class="STYLE9">：</span>&nbsp;</td>
                            <td height="30" colspan="2"><input type="text" name="pay_email" size="26"/></td>
                          </tr>
                          <tr>
                            <td height="30" colspan="3"><!--DWLayoutEmptyCell-->&nbsp;</td>
                          </tr>
                          <tr>
                            <td height="50"  align="center"><input height="50" width="50" type="submit" class="STYLE1" value="确定付款"/></td>
                            <td height="50"  align="center"><input height="50" width="50" name="button" type="submit" class="STYLE1" value="取消付款" onClick="history.go(-1);"/></td>
                          </tr>
                        </table>
						</form> 
          </div><!-- .total -->
        </div><!-- ply -->

        <div class="clear"></div>
      </div><!-- #content_bottom -->
      <div class="clear"></div>

      <div class="clear"></div><br></div><div class="clear"></div>

  <footer>
    <div class="f_info">
      <div class="container_12">
        <div class="grid_6">
          <p class="copyright">BY 417工作室, 2015</p>
        </div><!-- .grid_6 -->

        <div class="grid_6">
          <div class="soc">
 
          </div><!-- .soc -->
        </div><!-- .grid_6 -->

        <div class="clear"></div>
      </div><!-- .container_12 -->
    </div><!-- .f_info -->
  </footer>
  <%}%>
  <%} %>
</body>
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
</html>
